﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using System.IO;

public class CpManage : MonoBehaviour
{
    private Button button;//获取关卡的按钮组件
    private Transform[] cpChild=new Transform[2];//获取关卡对应的子物体
    [Tooltip("是否开启关卡")]
    private bool isOpen;
    /// <summary>
    /// 属性
    /// </summary>
    public bool IsOpen
    {
        get { return isOpen; }
        set
        {
            #region 开启关卡
            if (value)
            {
                if (cpChild[1]!=null)
                {
                    cpChild[1].gameObject.SetActive(false);
                    button.interactable = true;
                }
            }
            #endregion
            isOpen = value;
        }
    }
    // Use this for initialization
    void Awake () {
        button = gameObject.GetComponent<Button>();
        int i = 0;
        foreach (Transform child in transform)
        {
            cpChild[i] = child;//获取子物体
            i++;
        }
        button.onClick.AddListener(ClickPoint);//为该组件添加点击事件
    }

    private void ClickPoint()
    {
        Time.timeScale = 1;
        if (SetMManager.Instance != null)
            SetMManager.Instance.PlayMusic(1);
        LoadManager.Instance.Loading(int.Parse(cpChild[0].GetComponent<Text>().text)+2);
    }//点击事
}
